package no.mehdi.game.service;

import java.util.Random;

import org.springframework.util.StringUtils;

/**
 * Read the list of creatures from gameconfig.properties and generate randomly a
 * new creature.
 * 
 * @author Mehdi Zare
 * 
 */
public class CreatureGenerator {
	/** The creatureList */
	private String[] creatureList;
	/** An instance of {@link Random}*/
	private Random random;

	/**
	 * Constructor to read a comaseparated list and make an array.
	 * 
	 * @param creatureList
	 *            the String list of creature
	 */
	public CreatureGenerator(String creatureList) {
		this.creatureList = StringUtils.commaDelimitedListToStringArray(creatureList);
		random = new Random();
	}

	/**
	 * Generate a new creature.
	 * 
	 * @return a creature.
	 */
	public String generateCreature() {
		return creatureList[random.nextInt(creatureList.length)];
	}

	/**
	 * Get teh creatureList.
	 * 
	 * @return the creatureList
	 */
	public String[] getCreatureList() {
		return creatureList;
	}
}
